package com.ww.word.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;

import com.ww.word.R;
import com.ww.word.entity.Word;
import com.ww.word.ui.HistoryViewActivity;


/**
 * @since 
 * @version 2013-12-12
 * @author wangwei
 */
public class HistoryAdapter extends BaseAdapter {
	private Context context;
	private List<String> list;
	private LayoutInflater lif;
	private List<Word> wordList;
	GridView grid;
	public List<String> getList() {
		return list;
	}

	public void setList(List<String> list) {
		this.list = list;
	}

	public HistoryAdapter(Context context, List<String> list) {
		this.context = context;
		this.list = list;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		final MyView mv;
		if (convertView == null) {
			mv = new MyView();
			lif = LayoutInflater.from(context);// 转化到context这个容器
			convertView = lif.inflate(R.layout.activity_history_item, null);// 设置要转化的layout文件
			mv.button = (Button) convertView.findViewById(R.id.button);// 取得实例
			convertView.setTag(mv);
		} else {
			mv = (MyView) convertView.getTag();
		}
		mv.button.setText( list.get(position));
		mv.button.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(context, HistoryViewActivity.class);
				intent.putExtra("time",  list.get(position));
				context.startActivity(intent);
			}});
		return convertView;
	}
	
	public static class MyView {
		Button button;
	}
}
